/*******************************************************************************
 *
 * Copyright (c) 2008-2011 ayound@gmail.com
 * This program and the accompanying materials
 * are made available under the terms of the GNU GENERAL PUBLIC LICENSE
 * which accompanies this distribution, and is available at
 * http://dev.perl.org/licenses/gpl1.html
 * All rights reserved.
 *
 * Created on 2009-11-10
 *******************************************************************************/
package org.ayound.skin.editor.core.convert;

import java.awt.Color;

import org.ayound.skin.editor.core.ColorFillFilter;
import org.ayound.skin.editor.core.HSBFilter;
import org.ayound.skin.editor.core.convert.helper.ColorHelper;
import org.ayound.skin.editor.core.convert.model.SkinModel;

public class ColorConverter {
	private SkinModel model;
	public ColorConverter(SkinModel model) {
		this.model = model;
	}

	public int convert(String colorStr) {
		return convert(ColorHelper.string2Color(colorStr));

	}
	public int convert(int vlaue) {
		Color color = new Color(vlaue);
		Color newColor = convert(color);
		return newColor.getRGB();
	}

	private Color convert(Color color) {
		HSBFilter hsbFilter = new HSBFilter();
		hsbFilter.setHue(model.getHue());
		hsbFilter.setSaturation(model.getSaturation());
		hsbFilter.setBrightness(model.getBrightness());
		Color newColor = hsbFilter.convert(color);
		ColorFillFilter fillFilter = new ColorFillFilter();
		fillFilter.setRed(model.getRed());
		fillFilter.setBlue(model.getBlue());
		fillFilter.setGreen(model.getGreen());
		newColor = fillFilter.convert(newColor);

		return newColor;
	}

	public SkinModel getModel() {
		return model;
	}

	public void setModel(SkinModel model) {
		this.model = model;
	}
}
